const Service = require('egg').Service;
class carService extends Service {
  async login(req) {
    const sql=`SELECT pwd,id FROM user WHERE email='${req.email}'`
    const data = await this.app.mysql.query(sql);
    if(data[0]==undefined){
        return 
    }else{
        return data[0]
    }
  }
  async register(obj){
    const sql=`SELECT * FROM user WHERE email='${obj.email}'`
    const data = await this.app.mysql.query(sql);
    if(data[0]!=undefined){
      return {code:4002} //邮箱已被注册返回code码4002
    }else{
      // console.log(111111)
      const sql = `INSERT  INTO user (email,  pwd) VALUES('${obj.email}', '${obj.pwd}')`
      const data = await this.app.mysql.query(sql);
      return {code:2001} //注册成功返回code码2001
    }
  }
}
module.exports = carService;